﻿//-----------------------------------------------------------------
//
// @(#)$Id: left2.aspx.cs,v 1.0 2013/12/16 9:56:23 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/16 9:56:23 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_SystemTableAdapters;

public partial class left2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["UserId"] == null)
            {
            }
            else {
                Response.Write("<script>" + GetIndexJson() + "</script>");
                string userId = Session["UserId"].ToString();
                Response.Write(GetRight(userId));
            }
        }
    }

    protected string GetRight(string userId)
    {
        System.Text.StringBuilder memuBuilder = new System.Text.StringBuilder();
        DataTable tableMemu = new T_MemuContextTableAdapter().GetUserMemuByUserId(userId);
        DataTable tableRight = new T_RightContextTableAdapter().GetUserRightByUserId(userId);

        int i = 0;
        DataRow[] nRow = tableMemu.Select("", "SortId");
        memuBuilder.Append("<div class=\"LeftNote\"><img src=\"Images/MenuTop.jpg\" style=\"width: 182px\"/><br /><img src=\"Images/menu_topline.gif\" alt=\"\"/>");
        foreach (DataRow rNo in nRow)
        {
            memuBuilder.Append(" <div class=\"Menu\">&nbsp;<img  class=\"MemuImg\"  src=\"Images/" + rNo["PicName"].ToString() + "\"/>&nbsp;" + rNo["SysName"].ToString() + "</div>").Append("\r\n");

            if (i == 0)
            {
                memuBuilder.Append("<div class=\"MenuNote\" style=\"display:block;\">").Append("\r\n");
            }
            else
            {
                memuBuilder.Append("<div class=\"MenuNote\" style=\"display:none;\">").Append("\r\n");
            }
            memuBuilder.Append("<img src=\"images/menu_topline.gif\" alt=\"\" />").Append("\r\n");
            string newChildNode = "";
            string oldChildNode = "";
            DataRow[] cRow = tableRight.Select("SysId='" + rNo["SysId"].ToString() + "'", "SortId1");

            foreach (DataRow r in cRow)
            {
                newChildNode = r["SubSysId"].ToString();
                if (oldChildNode != newChildNode)
                {
                    switch (newChildNode)
                    {
                        // Message
                        case "0602":
                            memuBuilder.Append("<div class=\"CMenu\">&nbsp;" + r["SubSysName"].ToString() + "</div>").Append("\r\n");
                            memuBuilder.Append("<div class=\"CMenuNote\" style=\"display:none;\">").Append("\r\n");
                            memuBuilder.Append("<a id=\"msgrefresh\" class=\"easyui-linkbutton\" data-options=\"plain:true,iconCls:'icon-reload'\" style=\"float:right;\"></a>").Append("\r\n");
                            memuBuilder.Append("<ul id=\"message\" class=\"easyui-tree MenuUL\" data-options=\"data: msgData\"></ul></div>").Append("\r\n");
                            break;
                        // dispute
                        case "0603":
                            memuBuilder.Append("<div class=\"CMenu\">&nbsp;" + r["SubSysName"].ToString() + "</div>").Append("\r\n");
                            memuBuilder.Append("<div class=\"CMenuNote\" style=\"display:none;\">").Append("\r\n");
                            memuBuilder.Append("<a id=\"disputerefresh\" class=\"easyui-linkbutton\" data-options=\"plain:true,iconCls:'icon-reload'\" style=\"float:right;\"></a>").Append("\r\n");
                            memuBuilder.Append("<ul id=\"dispute\" class=\"easyui-tree MenuUL\" data-options=\"data: disputeData\"></ul></div>").Append("\r\n");
                            break;
                        // feedback
                        case "0604":
                            memuBuilder.Append("<div class=\"CMenu\">&nbsp;" + r["SubSysName"].ToString() + "</div>").Append("\r\n");
                            memuBuilder.Append("<div class=\"CMenuNote\" style=\"display:none;\">").Append("\r\n");
                            memuBuilder.Append("<a id=\"feedbackrefresh\" class=\"easyui-linkbutton\" data-options=\"plain:true,iconCls:'icon-reload'\" style=\"float:right;\"></a>").Append("\r\n");
                            memuBuilder.Append("<ul id=\"feedback\" class=\"easyui-tree MenuUL\" data-options=\"data: feedbackData\"></ul></div>").Append("\r\n");
                            break;
                        default:
                            memuBuilder.Append("<div class=\"CMenu\">&nbsp;" + r["SubSysName"].ToString() + "</div>").Append("\r\n");
                            memuBuilder.Append("<div class=\"CMenuNote\" style=\"display:block;\">").Append("\r\n");
                            memuBuilder.Append("<ul class=\"MenuUL\">").Append("\r\n");
                            DataRow[] rs = tableRight.Select("SubSysId='" + newChildNode + "'");

                            foreach (DataRow rm in rs)
                            {
                                memuBuilder.Append("<li><a href=\"" + rm["ProgExecName"].ToString() + "\" onclick = \"parent.LoadUrl('" + rm["ProgName"].ToString() + "','" + rm["ProgExecName"].ToString() + "');return false;\"> &nbsp;&nbsp;&nbsp;&nbsp;" + rm["ProgName"].ToString() + "</a></li>").Append("\r\n");
                            }
                            memuBuilder.Append("</ul>").Append("\r\n");
                            memuBuilder.Append("</div>").Append("\r\n");
                            break;
                    }

                    oldChildNode = newChildNode;
                }
            }
            i++;
            memuBuilder.Append("</div>").Append("\r\n");
        }
        memuBuilder.Append("</div>").Append("\r\n");
        return memuBuilder.ToString();
    }

    public String GetIndexJson() {
        System.Text.StringBuilder builder = new System.Text.StringBuilder();
        ebay.BLL.MailManage manage = new ebay.BLL.MailManage();

        builder.Append("var msgData=").Append(manage.GetMessageTreeData()).Append(";");
        builder.Append("\r\n");
        builder.Append("var disputeData=").Append(manage.GetDisputeTreeData()).Append(";");
        builder.Append("\r\n");
        builder.Append("var feedbackData=").Append(manage.GetFeedbackTreeData()).Append(";");
        builder.Append("\r\n");

        return builder.ToString();
    }
}
